<?php

namespace App\Http\Controllers\Baidu;

use Illuminate\Http\Request;
use	Exception;

include_once ('../app/libary/Baidu/sms_service_AdgroupService.php');

use sms_service_AdgroupService;

use GetAdgroupRequest;

//use App\Http\Controllers\Baidu\CampaignController;
class AdgroupController
{
    var $adgroup;
    var $adrequest;
    var $campaign;

    public function __construct()
    {
        $this->adgroup = new sms_service_AdgroupService();
        $this->adrequest = new GetAdgroupRequest();
        $this->campaign = new CampaignController();

    }


    /**
     * @return mixed|string|void
     * 据指定的单元 id 获取推广单元
     */
    public function getAdgroupData()
    {
        $campaignId = [];
        $result = $this->campaign->getCampaign();
        $result = json_decode($result);
        foreach($result->body as $value )
        {
            $campaignId[] .= $value[0]->campaignId;
        }

        $aadgroupFields = [
            'adgroupId','campaignId','adgroupName','pause','maxPrice','negativeWords','exactNegativeWords',
            'status','accuPriceFactor','wordPriceFactor','widePriceFactor','matchPriceStatus','priceRatio',
            'pcPriceRatio',
        ];
        $idType = 3;
        $ids = $campaignId;
        $this->adrequest->setAdgroupFields($aadgroupFields);
        $this->adrequest->setIdType($idType);
        $this->adrequest->addId($ids);

        $data = $this->adgroup->getAdgroup($this->adrequest);
        return json_encode($data);

    }
    
} 